package com.example.zxw.net

import com.example.zxw.CnsApplication
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import utils.DeviceInfoUtil

/**
 * @author: user
 * @date: 2022/11/16
 */

private val okHttpClient by lazy {
    OkHttpClient.Builder()
        .addInterceptor {
            chain ->
            val request = chain.request()
            val build = request.newBuilder()
                .header("timestamp", System.currentTimeMillis().toString())
//                .header("sign", getAccessTokenAesSign())
//                .header("accessToken", accessToken)
                .header("version_chinanews", DeviceInfoUtil.getAppVersionName(CnsApplication.applicationContext))
                .header("deviceId_chinanews", DeviceInfoUtil.getDeviceId(CnsApplication.applicationContext))
                .header("platform_chinanews", "android")
                .header("source", "chinanews")
                .header("appKey", "CNSAPP")
                .build()
            chain.proceed(build)
        }
        .build()
}

private val retrofit by lazy {
    Retrofit.Builder()
        .client(okHttpClient)
        .addConverterFactory(GsonConverterFactory.create())
        .baseUrl(ApiUrl.BASE_NES)
        .build()
}

object NewsApiService : NewsApi by retrofit.create(NewsApi::class.java)


